package com.ruoyi.web.controller.system;

import java.util.List;
import com.ruoyi.system.domain.StringId;
import javax.servlet.http.HttpServletResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BEAffile;
import com.ruoyi.system.service.IBEAffileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.comment.FileComment;

/**
 * 文件管理审核后Controller
 * 
 * @author ruoyi
 * @date 2024-06-24
 */
@RestController
@RequestMapping("/system/affile")
public class BEAffileController extends BaseController
{
    @Autowired
    private IBEAffileService bEAffileService;

    /**
     * 查询文件管理审核后列表
     */
//    @PreAuthorize("@ss.hasPermi('system:affile:list')")
    @GetMapping("/list")
    public TableDataInfo list(BEAffile bEAffile)
    {
        startPage();
        List<BEAffile> list = bEAffileService.selectBEAffileList(bEAffile);
        return getDataTable(list);
    }

    /**
     * 导出文件管理审核后列表
     */
//    @PreAuthorize("@ss.hasPermi('system:affile:export')")
    @Log(title = "文件管理审核后", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BEAffile bEAffile)
    {
        List<BEAffile> list = bEAffileService.selectBEAffileList(bEAffile);
        ExcelUtil<BEAffile> util = new ExcelUtil<BEAffile>(BEAffile.class);
        util.exportExcel(response, list, "文件管理审核后数据");
    }


    /**
     * 查询文件注释信息列表
     *
     * @return 文件信息集合
     */
    @PostMapping("/getAffileComment")
    public List<FileComment> getAffileComment() {
        return bEAffileService.selectBEAffileComList();
    }


    /**
     * 获取文件管理审核后详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:affile:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(bEAffileService.selectBEAffileById(id));
    }

    /**
     * 新增文件管理审核后
     */
//    @PreAuthorize("@ss.hasPermi('system:affile:add')")
    @Log(title = "文件管理审核后", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BEAffile bEAffile)
    {
        return toAjax(bEAffileService.insertBEAffile(bEAffile));
    }

    /**
     * 修改文件管理审核后
     */
//    @PreAuthorize("@ss.hasPermi('system:affile:edit')")
    @Log(title = "文件管理审核后", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BEAffile bEAffile)
    {
        return toAjax(bEAffileService.updateBEAffile(bEAffile));
    }

    /**
     * 删除文件管理审核后
     */
//    @PreAuthorize("@ss.hasPermi('system:affile:remove')")
    @Log(title = "文件管理审核后", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(bEAffileService.deleteBEAffileByIds(ids));
    }


    /**
     * 查询文件信息通过id
     */
    @PostMapping("/getAffileById")
    public AjaxResult getAffileInfoById(@RequestBody StringId stringId) {
        if (stringId.getIds() != null) {
            String[] stringList = stringId.getIds();
            String id = stringList[0];
            return success(bEAffileService.selectBEAffileById(id));
        } else {
            String id = stringId.getId();
            return success(bEAffileService.selectBEAffileById(id));
        }
    }

    /**
     * 获取二进制文件
     */
    @PostMapping("/getPdf")
    public ResponseEntity<byte[]> getPdf(@RequestBody BEAffile File) {
        return bEAffileService.getpdf(File.getId());
    }

    @GetMapping("downloadMore/{ids}")
    public ResponseEntity<byte[]> downloadMore(@PathVariable String[] ids) {
        return bEAffileService.downloadMore(ids);
    }

}
